{extend name="$BASE_LIST" /}
{block name="body"}
<div class="right-main">
    <div class="page_nav" id="js_page_nav"><span class="page_title">签到设置</span></div>
    <div id="js_main_header" class="ui-form main_header">
        <span class="right">
            <button type="button" id="js_addBtn" class="btn btn-primary"><i class="icon wb-plus"></i> 添加签到</button>
        </span>
    </div>
    <table id="grid-table">
        <thead>
        <tr>
            <th data-options="field:'days',width:120,align:'center'">签到天数</th>
            <th data-options="field:'amount',width:120,align:'center'">奖励数量</th>
            <th data-options="field:'update_time',width:120,align:'center'">修改时间</th>
            <th data-options="field:'_oper',halign:'center',formatter: formatOper">操作</th>
        </tr>
        </thead>
    </table>
</div>

{/block}
{block name="script"}
<script type="text/javascript">

    function formatOper(value, row, index) {
        var html = '<span class="grid-operation">';
        html += '<button type="button" onclick="edit(' + row['id'] + ')" class="btn btn-xs btn-default edit-btn"><i class="icon wb-edit"></i>编辑</button>';
        html += '<button type="button" onclick="del(' + row['id'] + ')" class="btn btn-xs btn-default del-btn"><i class="icon wb-close"></i>删除</button>';
        html += '</span>';
        return html;
    }

    $(function () {
        $('#grid-table').datagrid({
            url: getURL('loadList'),
            method: "GET",
            height: getGridHeight(),
            rownumbers: true,
            singleSelect: true,
            remoteSort: false,
            multiSort: true,
            emptyMsg: '<span>无相关数据</span>',
            pagination: true,
            pageSize: 20
        });
        //设置分页控件
        $('#grid-table').datagrid('getPager').pagination({
            pageSize: 20, //每页显示的记录条数，默认为10
            pageList: [20, 30, 50]
        });
    });

    function edit(id) {
        var url = getURL('news_post', 'id=' + id);
        openBarWin('编辑签到', 1000, 600, url, function () {
            reload();
        }, ['保存', '取消']);
    }

    function del(id) {
        confirm("确认要删除此签到吗？", function () {
            var url = getURL('del');
            $.getJSON(url, {id: id}, function (json) {
                if (json.success)
                    reload();
                else
                    alert(json.message);
            });
        });
    }

    $("#js_addBtn").click(function () {
        if ($(this).hasClass("disabled")) {
            return;
        }
        var url = getURL('news_post');
        openBarWin('添加签到', 1000, 600, url, function () {
            reload();
        });
    });
    $("#js_search").click(function () {
        reload();
    });
    function reload() {
        var type = $("#type").val();
//        var status = $("#status").val();
        var keyword = $("#js_keyword").val();
        $('#grid-table').datagrid('reload', {keyword: keyword});
    }
    //    $("#status").change(function () {
    //        reload();
    //    });
    $("#type").change(function () {
        var type = $(this).val();
        var keyword = $("#js_keyword").val();
        $('#grid-table').datagrid('reload', {keyword: keyword,category_id:type});
    });
</script>
{/block}